package com.xiao.hao.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @Desciption:
 * @Author: 郑焱军
 * @Date: 2022/8/17 16:14
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> implements Serializable {
    /**
     * 总数
     */
    private Integer total;
    /**
     * 是否成功：
     */
    private Integer resp_code;

    private String resp_msg;
    /**
     * 当前页结果集
     */
    private List<T> datas;

    public static <T> PageResult<T> result(long total, List<T> list) {
        return new PageResult<>(Integer.valueOf(Math.toIntExact(total)), 200, "SUCCESS", list);
    }

    public static <T> PageResult<T> result(Integer total, List<T> list) {
        return new PageResult<>(total, 200, "SUCCESS", list);
    }

    public static <T> PageResult<T> result(Integer total, List<T> list, String msg) {
        return new PageResult<>(total, 200, msg, list);
    }

}
